<template>
  <!-- 搜索框 -->
  <MyFilter :partParams="basicParams" @get-data="getData" @open-modal="openModal" />
  <!-- 列表 -->
  <MyTable ref="table" :partParams="tableParams" />
  <!-- 新增弹框 -->
  <AddModal ref="modalRef" :partParams="basicParams" @refresh="refresh" />
</template>

<script lang="ts" setup>
import { objectToQueryParams } from '@/utils/objectToQuery'
import MyFilter from './MyFilter.vue'
import MyTable from './MyTable.vue'
import AddModal from './AddModal.vue'
import { defineProps, ref } from 'vue'
import * as BasicApi from '@/api'
import { useMessage } from '@/hooks/useMessage'

//定义接收的props
const props = defineProps({
  // 定义一个对象类型的 prop
  data: {
    type: Object,
    default: () => ({ groupName: '', jobType: '' })
  }
})

const basicParams = {
  groupName: props.data.groupName,
  jobType: props.data.jobType,
  operType: 'GetList'
}

const tableParams = ref()

const table = ref()
/** 查询列表 */
const getData = async (query: any) => {
  tableParams.value = JSON.parse(JSON.stringify(query))
}

const message = useMessage()
//新增
const modalRef = ref()
const openModal = async () => {
  const inputStr = objectToQueryParams({
    ...basicParams,
    operType: 'Add'
  })
  const res = (await BasicApi.Query({ inputStr })) as any
  if (res.code !== 200) {
    message.error(res.msg)
    return
  }
  // const { listInfo, fieldInfo } = res.data
  // const result = Object.entries(fieldInfo)

  // //结果集转换为表单格式
  // const post = result.map((item) => {
  //   return {
  //     ...item[1],
  //     key: item[0],
  //     value: listInfo[0][item[0]]
  //   }
  // })
  modalRef.value.open({groupName: 'test'})
}

const refresh = () => {
  tableParams.value = {
    ...basicParams,
    ...tableParams.value
  }
}
</script>
